package com.manage.widgets;

import com.manage.R;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

/**
 * 入账确认dialog
 * @author liyoro
 *
 */
public class AccountedConfirmDialog extends Dialog implements OnClickListener {

	private Button btnConfirm = null;
	private Button btnCancel = null;
	private EditText etFeedback = null;
	private EditText etPaidUp = null;
	
	private TextView tvReceivable = null;
	
    private Window window = null;

    private String defaultPrice = null;
    
    DialogActionListener dialogAction;
    
	public AccountedConfirmDialog(Context context, String paramString) {
		super(context);
		this.defaultPrice = paramString;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_accounted_confirm); 
        
        btnConfirm = (Button)findViewById(R.id.MenuQuitDialogOK);
        btnConfirm.setOnClickListener(this);
        btnCancel = (Button)findViewById(R.id.MenuQuitDialogCancel);
        btnCancel.setOnClickListener(this);
        
        tvReceivable = (TextView)findViewById(R.id.tv_receivable);
        
        etFeedback = (EditText)findViewById(R.id.et_feedback);
        etPaidUp = (EditText)findViewById(R.id.et_paid_up);
        
        tvReceivable.setText(defaultPrice);
        etPaidUp.setText(defaultPrice);
        
        //设置触摸对话框意外的地方取消对话框
        setCanceledOnTouchOutside(true);
	}

	@Override
	public void show() {
		super.show();
		windowDeploy(0, 0);
	}
	
	//设置窗口显示
    private void windowDeploy(int x, int y){
        window = getWindow(); //得到对话框
        window.setWindowAnimations(R.style.dialogWindowAnim); //设置窗口弹出动画
        window.setBackgroundDrawableResource(R.color.transparent); //设置对话框背景为透明
        WindowManager.LayoutParams wl = window.getAttributes();
        //根据x，y坐标设置窗口需要显示的位置
        wl.x = x; //x小于0左移，大于0右移
        wl.y = y; //y小于0上移，大于0下移  
//        wl.alpha = 0.6f; //设置透明度
//        wl.gravity = Gravity.BOTTOM; //设置重力
        window.setAttributes(wl);
    }
    
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.MenuQuitDialogOK:
			String paidup = etPaidUp.getText().toString().trim();
			String remark = etFeedback.getText().toString().trim();
			dialogAction.confirmAction(paidup, remark);
			break;
		case R.id.MenuQuitDialogCancel:
			dismiss();
			break;
		default:
			break;
		}
	}

	/**
	 * 接口方法，用于点击dialog中”确定“按钮的事件处理
	 * @param listener
	 */
	public void setDialogConfirmAction(DialogActionListener listener) {
		this.dialogAction = listener;
	}
}
